#ifndef GAMEENGINE_GRAPHICS_MESHES_MESH_RENDERER_H
#define GAMEENGINE_GRAPHICS_MESHES_MESH_RENDERER_H

#include <GameEngine/Graphics/graphics_settings.h>

#include <GameEngine/Graphics/Scene/scene_element.h>
#include <GameEngine/Graphics/display_list.h>
#include <GameEngine/Graphics/Transformation/gl_transformer3d.h>


#ifdef GAMEENGINE_NAMESPACES
namespace GameEngine {
#endif

class SurfaceMesh;

//! API for the rendering of a surface mesh
/*!
 *  A mesh renderer is responsible for the on-screen rendering of a mesh. The mesh renderer uses a display
 *  list to accelerate the rendering of opaque geometry (but must redraw transparent geometry at each frame).
 *
 *  The mesh renderer also uses an OpenGL 3D transformer to handle the geographic location and the orientation
 *  of the mesh being rendered.
 */
class _Graphics_decl MeshRenderer : public SceneElement {

public:
	MeshRenderer(SurfaceMesh* mesh = nil);
	MeshRenderer(const MeshRenderer& rhs);
	MeshRenderer& operator=(const MeshRenderer& rhs);
	virtual ~MeshRenderer();

	GLTransformer3d& transformer();
	const GLTransformer3d& transformer() const;

	void set_mesh(SurfaceMesh* mesh = nil);
	bool valid() const;

	virtual bool draw(const Line3d<float>& ray);

protected:
	//! Mesh associated to the mesh renderer
	SurfaceMesh* mesh_;

	//! Display list used to accelerate the rendering of the mesh in static mode
	DisplayList list_;

	//! 3D transformer that changes the coordinates of the mesh on the GPU
	GLTransformer3d transformer_;
};


#ifdef GAMEENGINE_NAMESPACES
} // namespace GameEngine
#endif

#endif
